<template>
	<div class="system-user-container layout-padding">
		<el-row :gutter="8" style="width: 100%">
			<el-col :span="4" :xs="24">
				<OrgTree ref="orgTreeRef" @node-click="nodeClick" />
			</el-col>
		</el-row>
	</div>
  </template>
  
  <script lang="ts" setup name="systemUser">
	import { onMounted, reactive, ref } from 'vue';
	import { ElMessageBox, ElMessage } from 'element-plus';
	// import { formatDate } from '/@/utils/formatTime';
	// import { auth } from '/@/utils/authFunction';
	// import OrgTree from '/@/views/system/org/component/orgTree.vue';
	// import EditUser from '/@/views/system/user/component/editUser.vue';

	// import { getAPI } from '/@/utils/axios-utils';
	// import { SysUserApi, SysOrgApi } from '/@/api-services/api';
	// import { SysUser, SysOrg } from '/@/api-services/models';


	// 引入组件
const OrgTree = defineAsyncComponent(() => import('/@/views/system/org/orgTree.vue'));
//const GrantDialog = defineAsyncComponent(() => import('/@/views/system/role/grant.vue'));

	const orgTreeRef = ref<InstanceType<typeof OrgTree>>();
	//const editUserRef = ref<InstanceType<typeof EditUser>>();
	const state = reactive({
		// loading: false,
		// userData: [] as Array<SysUser>,
		// orgTreeData: [] as Array<SysOrg>,
		// queryParams: {
		// 	orgId: -1,
		// 	account: undefined,
		// 	realName: undefined,
		// 	phone: undefined,
		// },
		// tableParams: {
		// 	page: 1,
		// 	pageSize: 20,
		// 	total: 0 as any,
		// },
		// editUserTitle: '',
	});

	onMounted(async () => {
		// loadOrgData();
		// handleQuery();
	});

	// // 查询机构数据
	// const loadOrgData = async () => {
	// 	state.loading = true;
	// 	var res = await getAPI(SysOrgApi).apiSysOrgListGet(0);
	// 	state.orgTreeData = res.data.result ?? [];
	// 	state.loading = false;
	// };

	// // 查询操作
	// const handleQuery = async () => {
	// 	state.loading = true;
	// 	let params = Object.assign(state.queryParams, state.tableParams);
	// 	var res = await getAPI(SysUserApi).apiSysUserPagePost(params);
	// 	state.userData = res.data.result?.items ?? [];
	// 	state.tableParams.total = res.data.result?.total;
	// 	state.loading = false;
	// };

	// // 重置操作
	// const resetQuery = () => {
	// 	state.queryParams.orgId = -1;
	// 	state.queryParams.account = undefined;
	// 	state.queryParams.realName = undefined;
	// 	state.queryParams.phone = undefined;
	// 	handleQuery();
	// };

	// // 打开新增页面
	// const openAddUser = () => {
	// 	state.editUserTitle = '添加账号';
	// 	editUserRef.value?.openDialog({ id: undefined, birthday: '2000-01-01', sex: 1, orderNo: 100, cardType: 0, cultureLevel: 5 });
	// };

	// // 打开编辑页面
	// const openEditUser = (row: any) => {
	// 	state.editUserTitle = '编辑账号';
	// 	editUserRef.value?.openDialog(row);
	// };

	// // 删除
	// const delUser = (row: any) => {
	// 	ElMessageBox.confirm(`确定删除账号：【${row.account}】?`, '提示', {
	// 		confirmButtonText: '确定',
	// 		cancelButtonText: '取消',
	// 		type: 'warning',
	// 	})
	// 		.then(async () => {
	// 			await getAPI(SysUserApi).apiSysUserDeletePost({ id: row.id });
	// 			handleQuery();
	// 			ElMessage.success('删除成功');
	// 		})
	// 		.catch(() => {});
	// };

	// // 改变页面容量
	// const handleSizeChange = (val: number) => {
	// 	state.tableParams.pageSize = val;
	// 	handleQuery();
	// };

	// // 改变页码序号
	// const handleCurrentChange = (val: number) => {
	// 	state.tableParams.page = val;
	// 	handleQuery();
	// };

	// // 修改状态
	// const changeStatus = (row: any) => {
	// 	getAPI(SysUserApi)
	// 		.apiSysUserSetStatusPost({ id: row.id, status: row.status })
	// 		.then(() => {
	// 			ElMessage.success('账号状态设置成功');
	// 		})
	// 		.catch(() => {
	// 			row.status = row.status == 1 ? 2 : 1;
	// 		});
	// };

	// // 重置密码
	// const resetUserPwd = async (row: any) => {
	// 	ElMessageBox.confirm(`确定重置密码：【${row.account}】?`, '提示', {
	// 		confirmButtonText: '确定',
	// 		cancelButtonText: '取消',
	// 		type: 'warning',
	// 	})
	// 		.then(async () => {
	// 			await getAPI(SysUserApi)
	// 				.apiSysUserResetPwdPost({ id: row.id })
	// 				.then((res) => {
	// 					ElMessage.success(`密码重置成功为：${res.data.result}`);
	// 				});
	// 		})
	// 		.catch(() => {});
	// };

	// 树组件点击
	const nodeClick = async (node: any) => {
		// state.queryParams.orgId = node.id;
		// state.queryParams.account = undefined;
		// state.queryParams.realName = undefined;
		// state.queryParams.phone = undefined;
		console.log('nId:'+node.id);
		handleQuery();
	};
	</script>

	<style scoped lang="scss">
	.system-user-container {
		:deep(.el-card__body) {
			display: flex;
			flex-direction: column;
			flex: 1;
			overflow: auto;
			.el-table {
				flex: 1;
			}
		}
	}
	</style>
